package org.akomantoso.core.data;

import java.io.IOException;

import org.akomantoso.core.data.attribute.Name;
import org.akomantoso.core.data.group.TLC;
import org.akomantoso.core.io.Input;
import org.akomantoso.core.io.Output;
import org.akomantoso.core.io.OutputUtil;

/**
 * The element TLCreference is a generic metadata reference to the Akoma Ntoso URI of an ontology instance of a class
 * specified through the name attribute.
 * 
 * <pre>
 * 	<xsd:element name="TLCReference">
 * 		<xsd:complexType>
 * 			<xsd:complexContent>
 * 				<xsd:extension base="referenceType">
 * 					<xsd:attributeGroup ref="name" />
 * 				</xsd:extension>
 * 			</xsd:complexContent>
 * 		</xsd:complexType>
 * 	</xsd:element>
 * </pre>
 * 
 * @author <a href="mailto:jacques.militello@gmail.com">Jacques Militello</a>
 * 
 * @since http://www.akomantoso.org/1.0
 */
public final class TLCReference extends ReferenceType implements TLC, Name {

	public static final String ELEMENT = "TLCReference";

	private String _name;

	/**
	 * @see org.akomantoso.core.data.attribute.Name#getName()
	 */
	public String getName() {
		return _name;
	}

	/**
	 * @see org.akomantoso.core.data.attribute.Name#setName(java.lang.String)
	 */
	public void setName(String name) {
		_name = name;
	}

	/**
	 * @see org.akomantoso.core.data.ReferenceType#writeExternal(org.akomantoso.core.io.Output)
	 */
	@Override
	public <T extends Output> void writeExternal(T out) throws IOException {
		out.writeStart(ELEMENT);
		OutputUtil.writeMandatoryAttribute(out, Name.ATTRIBUTE, _name,this);
		super.writeExternal(out);
		out.writeEnd();
	}

	/**
	 * @see org.akomantoso.core.data.ReferenceType#readExternal(org.akomantoso.core.io.Input)
	 */
	@Override
	public <T extends Input> void readExternal(T in) throws IOException {
		_name = in.readAttribute(Name.ATTRIBUTE);
		super.readExternal(in);
	}
	
}